import { ref, onMounted } from 'vue'
import { defineStore } from 'pinia'
import { getCategoryAPI } from '@/api/layout';
//使用pinia优化重复请求
export const useCategoryStore = defineStore('category', () => {
  const categoryList = ref([]);
  const getCategory = async() =>{
      const res = await getCategoryAPI();
      categoryList.value = res.result;//将接口得到result结果给categoryList值
  }
  onMounted(()=> getCategory())
  //一加载就调用
  return { categoryList,getCategory }
})
